; The name of the installer
Name "Mu"

!define MUI_PRODUCT "Mu Beta Ver. 0.5"

; The file to write
OutFile "Mu-0.5-beta.exe"

; The default installation directory
InstallDir $PROGRAMFILES\Mu

; Registry key to check for directory (so if you install again, it will 
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\Mu" "Install_Dir"

; Request application privileges for Windows Vista
RequestExecutionLevel admin

;--------------------------------

; Pages

Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------

; The stuff to install
Section "Mu (required)"

  SectionIn RO
  
  ; Set output path to the installation directory.
  SetOutPath $INSTDIR
  
  ; Put file there
  File "mu.exe"
  File "libgcc_s_dw2-1.dll"
  File "mingwm10.dll"
  File "qca2.dll"
  File "QtCore4.dll"
  File "QtGui4.dll"
  File "QtNetwork4.dll"
  File "QtXml4.dll"
  ; Include OpenSSL plugin related libraries
  File "libeay32.dll"
  File "libssl32.dll"
  File "ssleay32.dll"

  CreateDirectory "$INSTDIR\crypto"
  SetOutPath $INSTDIR\crypto
  File "crypto\qca-ossl2.dll"
  
  
  ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARE\Mu "Install_Dir" "$INSTDIR"
  
  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Mu" "DisplayName" "Mu"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Mu" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Mu" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Mu" "NoRepair" 1
  WriteUninstaller "uninstall.exe"
  
SectionEnd

; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"

  CreateDirectory "$SMPROGRAMS\Mu"
  CreateShortCut "$SMPROGRAMS\Mu\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
  CreateShortCut "$SMPROGRAMS\Mu\Mu.lnk" "$INSTDIR\mu.exe" "" "$INSTDIR\mu.exe" 0
  
SectionEnd

; Create desktop shortcut
Section "Desktop Shortcut"

  CreateShortCut "$DESKTOP\mu.lnk" "$INSTDIR\mu.exe" ""

SectionEnd
;--------------------------------

; Uninstaller

Section "Uninstall"
  
  ; Remove registry keys
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Mu"
  DeleteRegKey HKLM SOFTWARE\Mu

  ; Remove files and uninstaller
  Delete $INSTDIR\mu.exe
  Delete $INSTDIR\libgcc_s_dw2-1.dll
  Delete $INSTDIR\mingwm10.dll
  Delete $INSTDIR\qca2.dll
  Delete $INSTDIR\QtCore4.dll
  Delete $INSTDIR\QtGui4.dll
  Delete $INSTDIR\QtNetwork4.dll
  Delete $INSTDIR\QtXml4.dll
  Delete $INSTDIR\uninstall.exe
  ; Remove OpenSSL plugin related libraries
  Delete $INSTDIR\libeay32.dll
  Delete $INSTDIR\libssl32.dll
  Delete $INSTDIR\crypto\qca-ossl2.dll
  Delete $INSTDIR\ssleay32.dll

  RMDir $INSTDIR\crypto
  
  ; Remove shortcuts, if any
  Delete "$SMPROGRAMS\Mu\*.*"

  ; Remove directories used
  RMDir "$SMPROGRAMS\Mu"
  RMDir "$INSTDIR"

SectionEnd

;--------------------------------
;MessageBox Section


;Function that calls a messagebox when installation finished correctly
Function .onInstSuccess
  MessageBox MB_OK "You have successfully installed ${MUI_PRODUCT}. Use the desktop icon to start the program."
FunctionEnd


Function un.onUninstSuccess
  MessageBox MB_OK "You have successfully uninstalled ${MUI_PRODUCT}."
FunctionEnd
